package main

import (
	"fmt"
	"math"
)

func Sqrt(x float64) (z float64) {
	count := 0

	if x == 1 {
		z = 1
	} else {
		z = x / 2
		for {
			count++
			delta := (z*z - x) / (2 * z)
			if math.Abs(delta) > 0.000000001 {
				z -= delta
			} else {
				break
			}
		}
	}

	fmt.Printf("count:%d\n", count)
	return
}

func main() {
	fmt.Println(Sqrt(1) - math.Sqrt(1))
	fmt.Println(Sqrt(2) - math.Sqrt(2))
	fmt.Println(Sqrt(3) - math.Sqrt(3))
	fmt.Println(Sqrt(5) - math.Sqrt(5))
	fmt.Println(Sqrt(6) - math.Sqrt(6))
	fmt.Println(Sqrt(7) - math.Sqrt(7))
	fmt.Println(Sqrt(9) - math.Sqrt(9))
	fmt.Println(Sqrt(100) - math.Sqrt(100))

}
